package com.jz.community.moduleshopping.timeLimit.ui.adapter;

import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jz.community.moduleshopping.R;
import com.jz.community.moduleshopping.timeLimit.bean.LimitTimeBean;

import java.util.List;

/**
 * Created by Ani_H on 2017/10/12.
 */

public class LimitTimeAdapter extends BaseQuickAdapter<LimitTimeBean.EmbeddedBean.LimitTimeViewsBean, BaseViewHolder> {

    public LimitTimeAdapter(@LayoutRes int layoutResId, @Nullable List<LimitTimeBean.EmbeddedBean.LimitTimeViewsBean> data) {
        super(layoutResId, data);
        mData = data;//不用将List传进来，直接用mData=data
    }

    @Override
    protected void convert(BaseViewHolder helper, LimitTimeBean.EmbeddedBean.LimitTimeViewsBean entity) {
        String status = entity.getStatus();
        ImageView triangle = helper.getView(R.id.item_limit_triangle);
        TextView tv_status = helper.getView(R.id.item_limit_status);
        TextView tv_time = helper.getView(R.id.item_limit_time);
        LinearLayout time_ll = helper.getView(R.id.item_limit_parent);

        if (status.equals("1")) {
            //未开抢
            tv_status.setText("未开抢");
            tv_status.setTextColor(mContext.getResources().getColor(R.color.home_red));
            tv_time.setTextColor(mContext.getResources().getColor(R.color.home_red));
        } else if (status.equals("2")) {
            //抢购中
            tv_status.setText("抢购中");
            tv_status.setTextColor(mContext.getResources().getColor(R.color.home_red));
            tv_time.setTextColor(mContext.getResources().getColor(R.color.home_red));
        } else if (status.equals("3")) {
            //已结束
            tv_status.setText("已结束");
            tv_status.setTextColor(mContext.getResources().getColor(R.color.font_remind));
            tv_time.setTextColor(mContext.getResources().getColor(R.color.font_remind));
        }

        helper.setText(R.id.item_limit_time, entity.getLimitedTimeStr());

        if (entity.isSelected()) {
            triangle.setVisibility(View.VISIBLE);
            time_ll.setBackgroundColor(mContext.getResources().getColor(R.color.home_red));
            tv_status.setTextColor(mContext.getResources().getColor(R.color.white));
            tv_time.setTextColor(mContext.getResources().getColor(R.color.white));
        } else {
            triangle.setVisibility(View.INVISIBLE);
            time_ll.setBackgroundColor(mContext.getResources().getColor(R.color.limit_time_yellow));
        }

    }

    public void change(int oldPosition, int position) {
        mData.get(oldPosition).setSelected(false);
        mData.get(position).setSelected(true);
        notifyDataSetChanged();
    }
}
